
pkgname=perl
pkgver=5.26.2
pkgrel=2
pkgdesc="A highly capable, feature-rich programming language"
arch=('x86_64')
license=('GPL' 'PerlArtistic')
url="https://www.perl.org"
groups=('base')
depends=('gdbm' 'db' 'coreutils' 'glibc' 'sh')
provides=('perl-archive-tar=2.24'
          'perl-attribute-handlers=0.99'
          'perl-autodie=2.29'
          'perl-autoloader=5.74'
          'perl-autouse=1.11'
          'perl-b-debug=1.24'
          'perl-base=2.26'
          'perl-bignum=0.47'
          'perl-carp=1.42'
          'perl-compress-raw-bzip2=2.074'
          'perl-compress-raw-zlib=2.074'
          'perl-config-perl-v=0.28'
          'perl-constant=1.33'
          'perl-cpan-meta-requirements=2.140'
          'perl-cpan-meta-yaml=0.018'
          'perl-cpan-meta=2.150010'
          'perl-cpan=2.18'
          'perl-data-dumper=2.167'
          'perl-db_file=1.840'
          'perl-devel-ppport=3.35'
          'perl-devel-selfstubber=1.06'
          'perl-digest-md5=2.55'
          'perl-digest-sha=5.96'
          'perl-digest=1.17_01'
          'perl-dumpvalue=1.18'
          'perl-encode=2.88'
          'perl-encoding-warnings=0.13'
          'perl-env=1.04'
          'perl-experimental=0.016'
          'perl-exporter=5.72'
          'perl-extutils-cbuilder=0.280225'
          'perl-extutils-constant=0.23'
          'perl-extutils-install=2.04'
          'perl-extutils-makemaker=7.24'
          'perl-extutils-manifest=1.70'
          'perl-extutils-parsexs=3.34'
          'perl-file-fetch=0.52'
          'perl-file-path=2.12_01'
          'perl-file-temp=0.2304'
          'perl-filter-simple=0.93'
          'perl-filter-util-call=1.55'
          'perl-getopt-long=2.49'
          'perl-http-tiny=0.070'
          'perl-i18n-collate=1.02'
          'perl-i18n-langtags=0.42'
          'perl-if=0.0606'
          'perl-io-compress=2.074'
          'perl-io-socket-ip=0.38'
          'perl-io-zlib=1.10'
          'perl-io=1.38'
          'perl-ipc-cmd=0.96'
          'perl-ipc-sysv=2.07'
          'perl-json-pp=2.27400_02'
          'perl-lib=0.64'
          'perl-libnet=3.10'
          'perl-locale-codes=3.42'
          'perl-locale-maketext-simple=0.21_01'
          'perl-locale-maketext=1.28'
          'perl-math-bigint-fastcalc=0.5005'
          'perl-math-bigint=1.999806'
          'perl-math-bigrat=0.2611'
          'perl-math-complex=1.5901'
          'perl-memoize=1.03_01'
          'perl-mime-base64=3.15'
          'perl-module-corelist=5.20180414_26'
          'perl-module-load-conditional=0.68'
          'perl-module-load=0.32'
          'perl-module-loaded=0.08'
          'perl-module-metadata=1.000033'
          'perl-net-ping=2.55'
          'perl-params-check=0.38'
          'perl-parent=0.236'
          'perl-pathtools=3.67'
          'perl-perl-ostype=1.010'
          'perl-perlfaq=5.021011'
          'perl-perlio-via-quotedprint=0.08'
          'perl-pod-checker=1.73'
          'perl-pod-escapes=1.07'
          'perl-pod-parser=1.63'
          'perl-pod-perldoc=3.28'
          'perl-pod-simple=3.35'
          'perl-pod-usage=1.69'
          'perl-podlators=5.006'
          'perl-safe=2.40'
          'perl-scalar-list-utils=1.46_02'
          'perl-search-dict=1.07'
          'perl-selfloader=1.23'
          'perl-socket=2.020_03'
          'perl-storable=2.62'
          'perl-sys-syslog=0.35'
          'perl-term-ansicolor=4.06'
          'perl-term-cap=1.17'
          'perl-term-complete=1.403'
          'perl-term-readline=1.17'
          'perl-test-harness=3.38'
          'perl-test-simple=1.302073'
          'perl-test=1.30'
          'perl-text-abbrev=1.02'
          'perl-text-balanced=2.03'
          'perl-text-parsewords=3.30'
          'perl-text-tabs=2013.0523'
          'perl-thread-queue=3.12'
          'perl-thread-semaphore=2.13'
          'perl-threads-shared=1.56'
          'perl-threads=2.15'
          'perl-tie-file=1.02'
          'perl-tie-refhash=1.39'
          'perl-time-hires=1.9741'
          'perl-time-local=1.25'
          'perl-time-piece=1.31'
          'perl-unicode-collate=1.19'
          'perl-unicode-normalize=1.25'
          'perl-version=0.9917'
          'perl-xsloader=0.27')
source=("http://www.cpan.org/src/5.0/perl-${pkgver}.tar.xz"
        'perlbin.sh'
        'perlbin.csh')
options=('makeflags' '!purge' 'emptydirs')
sha256sums=('0f8c0fb1b0db4681adb75c3ba0dd77a0472b1b359b9e80efd79fc27b4352132c'
            '6681639f18f3a6f3f3d7f978b8d72ad088b27899a6fcc386b86ac104199d857b'
            '69c03f11e98c5c4af3cfd4900840189d19b74fe4fd4534523781312d0a1be810')

build() {
  cd ${pkgname}-${pkgver}

  ./Configure -des -Dusethreads -Duseshrplib -Doptimize="${CFLAGS}" \
    -Dprefix=/usr -Dvendorprefix=/usr \
    -Dprivlib=/usr/share/perl5/core_perl \
    -Darchlib=/usr/lib/perl5/core_perl \
    -Dsitelib=/usr/share/perl5/site_perl \
    -Dsitearch=/usr/lib/perl5/site_perl \
    -Dvendorlib=/usr/share/perl5/vendor_perl \
    -Dvendorarch=/usr/lib/perl5/vendor_perl \
    -Dscriptdir=/usr/bin/core_perl \
    -Dsitescript=/usr/bin/site_perl \
    -Dvendorscript=/usr/bin/vendor_perl \
    -Dinc_version_list=none \
    -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 \
    -Dman1ext=1perl -Dman3ext=3perl -Dcccdlflags='-fPIC' \
    -Dlddlflags="-shared ${LDFLAGS}" -Dldflags="${LDFLAGS}"

  make
}

check() {
  cd ${pkgname}-${pkgver}
  TEST_JOBS=$(echo $MAKEFLAGS | sed 's/.*-j\([0-9][0-9]*\).*/\1/') make test_harness || true
 
  make test
}

package() {
  cd ${pkgname}-${pkgver}
  LD_PRELOAD="/usr/lib/libfakeroot/libfakeroot.so" 
  make DESTDIR=${pkgdir} install

  ### Perl Settings ###
  # Change man page extensions for site and vendor module builds, no email address
  sed -e '/^man1ext=/ s/1perl/1p/' -e '/^man3ext=/ s/3perl/3pm/' \
      -e "/^cf_email=/ s/'.*'/''/" \
      -e "/^perladmin=/ s/'.*'/''/" \
      -i ${pkgdir}/usr/lib/perl5/core_perl/Config_heavy.pl

  ### CPAN Settings ###
  # Set CPAN default config to use the site directories.
  sed -e '/(makepl_arg =>/   s/""/"INSTALLDIRS=site"/' \
      -e '/(mbuildpl_arg =>/ s/""/"installdirs=site"/' \
      -i ${pkgdir}/usr/share/perl5/core_perl/CPAN/FirstTime.pm

  # Profile script to set paths to perl scripts.
  install -D -m755 ${srcdir}/perlbin.sh \
                   ${pkgdir}/etc/profile.d/perlbin.sh
  # Profile script to set paths to perl scripts on csh.  
  install -D -m755 ${srcdir}/perlbin.csh \
                  ${pkgdir}/etc/profile.d/perlbin.csh
  
  # add default dir                
  install -d -m755 ${pkgdir}/usr/bin/vendor_perl
  install -d -m755 ${pkgdir}/usr/bin/site_perl
  
  rm ${pkgdir}/usr/bin/perl$pkgver
  (cd ${pkgdir}/usr/bin/core_perl;  ln -sf c2ph pstruct; ln -sf s2p psed)

  # Remove all pod files *except* those under /usr/share/perl5/core_perl/pod/
  rm -f ${pkgdir}/usr/share/perl5/core_perl/*.pod
  for d in ${pkgdir}/usr/share/perl5/core_perl/*; do
    if [ -d $d -a $(basename $d) != "pod" ]; then
      find $d -name *.pod -delete
    fi
  done

  find ${pkgdir}/usr/lib -name *.pod -delete
  find ${pkgdir} -name .packlist -delete
}
